﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hisun.Controllers;

namespace Hisun.UserControl.CostCenterItem
{
    /// <summary>
    /// Copyright (C) 2008 HOHO``
    /// All rights reserved
    /// NameSpace:Hisun.UserControl.CostCenterItem.Upload
    /// Description :
    /// Created By QiuZhongJie At 2008/10/16 13:12
    /// </summary>
    public partial class Upload : System.Web.UI.UserControl
    {
        private string lastError;

        /// <summary>
        /// Gets the last error.
        /// </summary>
        /// <value>The last error.</value>
        public string LastError
        {
            get { return lastError; }
        }
        private Exception lastException;

        /// <summary>
        /// Gets the last exception.
        /// </summary>
        /// <value>The last exception.</value>
        public Exception LastException
        {
            get { return lastException; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

        }


        /// <summary>
        /// Does the save file.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        public int SaveFile(string filename)
        {

            if (FileUploadXls.HasFile == false || FileUploadXls.PostedFile.ContentLength <= 0)
            {
                lastError = "没有需要倒入的表格！";
                lastException = null;
                return -1;
            }
            System.IO.File.Delete(GetXlsFullSavePath(filename));
            FileUploadXls.SaveAs(GetXlsFullSavePath(filename));
            return 0;
        }


        /// <summary>
        /// Gets the XLS full save path.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        public string GetXlsFullSavePath(string filename)
        {
            return HttpContext.Current.Server.MapPath(ServerVars.sysCostItemsUploadsSavedPath + filename);
        }
    }
}